<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box">
				<text style="min-width: 100rpx; margin-right: 10rpx">
					共
					<text style="color: red">{{ totalNum }}</text
					>条
				</text>
				<u-search shape="square" placeholder="请输入客户名称" input-align="center" v-model="search" @clear="cancelSearch" @custom="getPageList" @search="getPageList"></u-search>
			</view>
			<swiper class="swiper-box" v-if="listData.length">
				<swiper-item class="swiper-item" @touchstart.stop="catchTouchMove">
					<scroll-view scroll-y style="height: 100%; width: 100%" :scroll-top="scrollTop" @scroll="changeScroll" @scrolltolower="reachBottom">
						<view class="page-box">
							<customer-list :listData="listData" :crmType="crmType" @touch-change="touchChange" @transfer-data="transferData"></customer-list>
							<u-loadmore :status="downStatus" bg-color="#f2f2f2"></u-loadmore>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
			<u-empty v-else mode="list"></u-empty>
			<view @click="addData" class="fixed-add-button" v-if="isSave && type != 'all'">
				<u-icon name="plus" class="fixed-add-icon"></u-icon>
			</view>
			<view @click="refreshData" class="fixed-refresh-button">
				<u-icon name="reload" class="fixed-refresh-icon" :style="{ transform: 'rotate(' + rotateNum + 'deg)' }"></u-icon>
			</view>
		</view>
		<view>
			<u-popup class="my-popup" v-model="showUserPopup" mode="bottom" :closeable="true" close-icon-pos="top-right" border-radius="10" close-icon-color="#c0c4cc" close-icon-size="40">
				<component :is="'TransferSelect'" v-if="showUserPopup" @value-change="fieldValueChange" :radio="true" :value="selectedCustomerInfo.customerId"></component>
			</u-popup>
		</view>
		<!-- 功能菜单 -->
		<u-action-sheet :list="showSheetList" v-model="sheetShow" @click="clickSheet"></u-action-sheet>
	</view>
</template>

<script>
import customerList from './components/customerList.vue';
import list from '../mixins/list.js';
import TransferSelect from '@/pages/customerManagement/common/components/TransferSelect';
import { crmCustomerTransfer } from '@/api/customer/customer.js';
export default {
	mixins: [list],
	data() {
		return {
			showUserPopup: false,
			sheetShow: false,
			sheetList: [
				{
					text: '转移',
					color: 'orange',
					type: 'transfer',
				},
				{
					text: '编辑',
					color: '#2979ff',
					type: 'update',
				},
			],
			showSheetList: [],
			selectedCustomerInfo: {},
		};
	},
	computed: {
		// crmType() {
		//     return this.vuex_user.crm.leads ? 'leads' : 'customer';
		// },
	},
	components: {
		customerList,
		TransferSelect,
	},
	onLoad(option) {},
	onShow() {},
	onPullDownRefresh() {
		//下拉
	},
	onReachBottom() {
		//上拉
	},
	methods: {
		transferData(data) {
			this.showUserPopup = true;
			console.log(data);
		},

		touchChange(value) {
			if (this.sheetList.length) {
				let arr = [];
				this.sheetList.map((item) => {
					if (this.vuex_user.crm.customer && this.vuex_user.crm.customer[item.type]) {
						if (item.type == 'update') {
							if (value.checkStatus == 5 || value.checkStatus == 4) {
								arr.push(item);
							}
						} else {
							arr.push(item);
						}
					}
				});
				this.showSheetList = arr;
				this.sheetShow = true;
				this.selectedCustomerInfo = value;
			}
		},

		clickSheet(index) {
			let sheet = this.showSheetList[index];
			if (sheet.type == 'transfer') {
				this.showUserPopup = true;
			}
			if (sheet.type == 'update') {
				let params = {
					crmType: this.crmType,
					id: this.selectedCustomerInfo.customerId,
					data: this.selectedCustomerInfo,
				};
				uni.navigateTo({
					url: '/pages/customerManagement/common/CrmCreateView?params=' + encodeURIComponent(JSON.stringify(params)),
				});
			}
		},

		fieldValueChange(data) {
			this.$api.customer.crmCustomerTransfer(data).then((res) => {
				this.showUserPopup = false;
				this.refreshData();
			});
		},
	},
};
</script>

<style lang="scss" scoped>
@import '@/pages/customerManagement/styles/list.scss';

.page-box {
	min-height: calc(100%-50rpx);
}

.my-popup /deep/ .u-close--top-right {
	top: 20rpx !important;
}

.my-popup /deep/ .u-drawer-content {
	height: 75% !important;
}

.list-item-active {
	color: #2979ff;
}
</style>
